<?php
require_once ('../../../src/db/connectdatabase.php');
require_once ("../../dao/AlbumDAO.php");

$result = false;

if(isset($_POST['act'])) {
	$action = $_POST['act'];
	if($action == 'edita') {// cho phep hien thi tren giao dien
		if(isset($_POST['type']) && isset($_POST['idpe'])) {
			$id = $_POST['idpe'];
			$isuse = $_POST['type'];
			$result = displayAlbum($id, $isuse);
		}
	} else if ($action == 'delalbum') {
		if(isset($_POST['idpe'])) {
			$id = $_POST['idpe'];
			if(deleteAlbumDetailByIDAlbum($id)) {// xoa toan bo du lieu trong album detail
				$result = deleteAlbum($id);
			}
		}
	} else if ($action == 'upddescipphoto') {// update mo ta photo
		if(isset($_POST['idpe']) && isset($_POST['cotent'])) {
			$id = $_POST['idpe'];
			$content = $_POST['cotent'];
			$result = updateDescriptonAlbumDetail($id, $content);
		}
	} else if ($action == 'delphoto') {// delete photo
		if(isset($_POST['idpe'])) {
			$id = $_POST['idpe'];
			$result = deleteAlbumDetail($id);
		}
	} else if ($action == 'upddescipalbum') {// update mo ta va ten album
		if(isset($_POST['idpe']) && isset($_POST['cotent']) && isset($_POST['name'])) {
			$idalbum = $_POST['idpe'];
			$namealbum = $_POST['name'];
			$content = $_POST['cotent'];
			$result = updateDescriptonAlbum($idalbum, $namealbum, $content);
		}
	}
}

echo json_encode($result);
?>